<template>
	<view class="u-wrap">
		<!-- 搜索框 -->
		<view class="u-search-box">
			<view class="u-nav-slot topsearch" slot="left">
				<u-search bg-color="#ffffff" placeholder="搜索你想要的功能" v-model="keyword" :animation="false"
					:showAction="false" @input="autoSearch()" :clearabled="false"
					:customActionStyle="customActionStyle" />
			</view>
		</view>
		<!-- banner图 -->
		<view class="banner-img">
			<image src="https://iflytts.oss-cn-qingdao.aliyuncs.com/website/img/webxzy/twoxze_4.png" mode=""></image>
		</view>
		<!-- 内容 -->
		<view class="u-menu-wrap">
			<scroll-view scroll-y scroll-with-animation class="u-tab-view menu-scroll-view" :scroll-top="scrollTop">
				<view v-for="(item,index) in navbar" :key="index" class="u-tab-item"
					:class="[current==index ? 'u-tab-item-active' : '']" :data-current="index"
					@tap.stop="swichMenu(index)">
					<text>{{item.name}}</text>
				</view>
			</scroll-view>
			<block v-for="(item,index) in tabbar" :key="index">
				<scroll-view scroll-y class="right-box" v-if="current==index">
					<view class="class-item">
						<view class="item-container">
							<view @click="goAibot(item1)" v-if="keyword.length == 0" class="thumb-box" v-for="(item1, index1) in item"
								:key="index1">
								<view class="item-menu-name">{{item1.name}}</view>
								<view class="item-menu-names">{{item1.subName}}</view>
							</view>
							<view @click="goAibot(items)" class="thumb-box" v-for="(items, indexs) in newList" :key="indexs">
								<view class="item-menu-name">{{items.name}}</view>
								<view class="item-menu-names">{{items.subName}}</view>
							</view>
						</view>
					</view>
				</scroll-view>
			</block>
		</view>
	</view>
</template>

<script>
	import classifyData from "@/api/classify.data.js";
	import {
		wycUrl,
		// wycUrlApi,
		// apiMixUrlApi,
		// apiMixUrlKeyApi
	} from '@/api/assemb.js'
	export default {
		data() {
			return {
				statementShows: false,
				ter: [{
						subName: "将文本改写成类似小红书的 Emoji风格。",
						firstContent: "请使用 Emoji 风格编辑以下段落，该风格以引人入胜的标题、每个段落中包含表情符号和在末尾添加相关标签为特点。请确保保持原文的意思。",
						name: "小红书风格",
						orderNum: 7
					},
					{
						subName: "将文本改写成类似小红书的 Emoji风格。",
						firstContent: "请使用 Emoji 风格编辑以下段落，该风格以引人入胜的标题、每个段落中包含表情符号和在末尾添加相关标签为特点。请确保保持原文的意思。",
						name: "小红书风格",
						orderNum: 7
					},
					{
						subName: "根据故事类型输出小说，例如奇幻浪漫或历史等类型。",
						firstContent: "我希望你能作为一个小说家。你要想出有创意的、吸引人的故事，能够长时间吸引读者。。我的第一个要求是 '小说类型'",
						name: "小说家",
						orderNum: 11
					},
					{
						subName: "辅助微信小程序开发。",
						firstContent: "作为 Vue3 开发人员，你的任务是使用 Yarn、Vite、Vue3、TS、Pinia 和 Vue…；在视图中显示中文文本；包括样式。请注意，您应该只提供满足这些要求所必需的代码；不需要解释或描述。",
						name: "开发:微信小程序",
						orderNum: 95,
					},
				],
				title: true,
				cenr: false,
				keyword: '',
				tabbar: '',
				navbar: classifyData,
				scrollTop: 0, //tab标题的滚动条位置
				current: 0, // 预设当前项的值
				menuHeight: 0, // 左边菜单的高度
				menuItemHeight: 0, // 左边菜单item的高度
				newList: ''
			}
		},
		onShow() {
			this.getInfo()
			// this.getInfos()
		},
		computed: {

		},
		methods: {
			// gopage(){
			//   uni.navigateTo({
			//   	url: '/pages/dialogue/dialogue'
			//   })
			// },
			goAibot(item) {
				uni.setStorageSync('aititle',item.name);
				uni.setStorageSync('newcontent',item.firstContent)
				uni.navigateTo({
					url: '/pages/webview/aigjweb?url=https://www.peiyine.com/aixzzj/aibot/index.html#/'
				});
			},
			autoSearch() {

				this.useingText()
			},
			useingText() {
				let that = this
				let cont = JSON.parse(JSON.stringify(this.tabbar))

				var arr = []; //定义数组
				for (var i in cont) {
					arr.push(cont[i]);
				}
				var list2 = [];
				// console.log(nav,'00000')
				arr.forEach((item, index) => {
					item.forEach((item1, index) => {
						if (that.keyword == '') {
							console.log('111')
							that.title = true
							return
						} // console.log(item1.name)
						if (item1.name.indexOf(that.keyword) >= 0) {
							list2.push(item1);
							that.cenr = true
							that.title = false
							console.log(true)
							this.newList = list2
						}
					})
				})
			},
			getInfo() {
				let that = this
				let param = {
					content: 'secondCategory'
				}
				wycUrl(param, 1018, 'getDictInfo').then((res) => {
					let tabbar = JSON.parse(res.data.data)
					let tab = tabbar[-1]
					console.log(tab)
					delete tabbar[-1]
					tabbar[0] = tab
					tabbar[13] = tab
					this.tabbar = tabbar
					console.log(this.tabbar)
				})
			},
			// getInfos(){
			// 	let param = {
			// 		content:'firstCategory'
			// 	}
			// 	wycUrl(param, 1018, 'getDictInfo').then( (res) => {
			// 		   console.log( JSON.parse(res.data.data),'-----')
			// 		   this.navbar = JSON.parse(res.data.data)
			// 		})

			// },

			getImg() {
				return Math.floor(Math.random() * 35);
			},
			// 点击左边的栏目切换
			async swichMenu(index) {
				if (index == this.current) return;
				this.current = index;
				console.log(this.current)
				// 如果为0，意味着尚未初始化
				if (this.menuHeight == 0 || this.menuItemHeight == 0) {
					await this.getElRect('menu-scroll-view', 'menuHeight');
					await this.getElRect('u-tab-item', 'menuItemHeight');
				}
				// 将菜单菜单活动item垂直居中
				this.scrollTop = index * this.menuItemHeight + this.menuItemHeight / 2 - this.menuHeight / 2;
			},
			// 获取一个目标元素的高度
			getElRect(elClass, dataVal) {
				new Promise((resolve, reject) => {
					const query = uni.createSelectorQuery().in(this);
					query.select('.' + elClass).fields({
						size: true
					}, res => {
						// 如果节点尚未生成，res值为null，循环调用执行
						if (!res) {
							setTimeout(() => {
								this.getElRect(elClass);
							}, 10);
							return;
						}
						this[dataVal] = res.height;
					}).exec();
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.topsearch {}

	.u-wrap {
		height: calc(100vh);
		/* #ifdef H5 */
		height: calc(100vh - var(--window-top));
		/* #endif */
		display: flex;
		flex-direction: column;
		background: #F5F5F5;
	}

	.u-search-box {
		padding: 0 24rpx;
	}

	.u-menu-wrap {
		flex: 1;
		display: flex;
		overflow: hidden;
		margin: 0 26rpx;
		padding-bottom: 30rpx;
	}

	.u-search-inner {
		background-color: rgb(234, 234, 234);
		border-radius: 100rpx;
		display: flex;
		align-items: center;
		padding: 10rpx 16rpx;
	}

	.u-search-text {
		font-size: 26rpx;
		color: $u-tips-color;
		margin-left: 10rpx;
	}

	.u-tab-view {
		width: 240rpx;
		height: 100%;
		background-color: rgba(255, 255, 255, 0.7);
		border-radius: 12rpx;
	}

	.u-tab-item {
		height: 100rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: flex-start;
		font-size: 24rpx;
		color: #333333;
		font-weight: 400;
		line-height: 1;
		padding: 0 23rpx;
	}

	.u-tab-item-active {
		position: relative;
		color: #358BFF;
		font-size: 24rpx;
		font-weight: bold;
	}

	.u-tab-item-active::before {
		content: "";
		position: absolute;
		left: 0;
		bottom: 26rpx;
		left: 26rpx;
		width: 14rpx;
		height: 2rpx;
		background: #358BFF;
	}

	.right-box {
		margin-left: 18rpx;
	}

	.page-view {}

	.class-item {
		margin-bottom: 30rpx;
		border-radius: 8rpx;
	}

	.item-title {
		font-size: 26rpx;
		color: black;
		font-weight: bold;
	}

	.item-menu-name {
		font-weight: normal;
		color: black;
		font-size: 29rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;
		margin-top: 25rpx;
		margin-left: 25rpx;
	}

	.item-menu-names {
		margin-top: 15rpx;
		font-weight: normal;
		font-size: 22rpx;
		color: #666666;
		padding-left: 25rpx;
		padding-right: 25rpx;
		overflow: hidden; //超出的文本隐藏
		text-overflow: ellipsis; //溢出用省略号显示
		display: -webkit-box; //将对象作为弹性伸缩盒子模型显示。
		-webkit-box-orient: vertical; //从上到下垂直排列子元素（设置伸缩盒子的子元素排列方式）
		-webkit-line-clamp: 2; //这个属性不是css的规范属性，需要组合上面两个属性，表示显示的行数。
	}


	.item-container {
		display: flex;
		flex-wrap: wrap;
	}

	.thumb-box {
		background: rgba(255, 255, 255, 0.7);
		width: 505rpx;
		height: 164rpx;
		border-radius: 12rpx;
		margin-top: 18rpx;
	}

	.thumb-box:first-child {
		margin-top: 0;
	}

	.item-menu-image {
		width: 120rpx;
		height: 120rpx;
	}

	.banner-img {
		display: flex;
		justify-content: center;
		margin: 30rpx 0rpx;

		image {
			width: 700rpx;
			height: 190rpx;
		}
	}
	
</style>
